package com.wswy.wyjk.model;

import android.os.Parcel;
import android.text.TextUtils;
import com.google.gson.annotations.SerializedName;

public class CityModel implements ICity{

    @SerializedName("name")
    public String name;

    @SerializedName("nameCn")
    public String pinyin;

    private transient int firstLetterId;
    private transient String firstLetter;

    private void initFirst(){

        if (firstLetter == null && !TextUtils.isEmpty(pinyin)){
            firstLetter = String.valueOf(pinyin.charAt(0)).toUpperCase();

            firstLetterId = firstLetter.charAt(0);

        }

    }

    @Override
    public String getCityName() {
        return name;
    }

    @Override
    public long getHeaderId() {
        initFirst();
        return firstLetterId;
    }

    @Override
    public String getNameLatter() {
        initFirst();
        return firstLetter;
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.name);
        dest.writeString(this.pinyin);
    }

    public CityModel(String name, String pinyin) {
        this.name = name;
        this.pinyin = pinyin;
    }

    public CityModel() {
    }

    protected CityModel(Parcel in) {
        this.name = in.readString();
        this.pinyin = in.readString();
    }

    public static final Creator<CityModel> CREATOR = new Creator<CityModel>() {
        @Override
        public CityModel createFromParcel(Parcel source) {
            return new CityModel(source);
        }

        @Override
        public CityModel[] newArray(int size) {
            return new CityModel[size];
        }
    };

    @Override
    public String toString() {
        return "CityModel{" +
                "name='" + name + '\'' +
                ", pinyin='" + pinyin + '\'' +
                '}';
    }
}
